#include "VerticalCardinal.h"

#include "CatanClassContractException.h"

namespace catan
{

/*static*/ std::vector<VerticalCardinal::Enum_VerticalCardinal> VerticalCardinal::vectorOfPossibleEnumValues;
/*static*/ std::vector<VerticalCardinal::Enum_VerticalCardinal> VerticalCardinal::vectorOfReducedPossibleEnumValues;

/*static*/ const std::vector<VerticalCardinal::Enum_VerticalCardinal> &VerticalCardinal::getVectorOfPossibleEnumValues()
{
	if (vectorOfPossibleEnumValues.empty())
	{
		vectorOfPossibleEnumValues.push_back(VERTICAL_TR);
		vectorOfPossibleEnumValues.push_back(VERTICAL_TC);
		vectorOfPossibleEnumValues.push_back(VERTICAL_TL);
		vectorOfPossibleEnumValues.push_back(VERTICAL_BL);
		vectorOfPossibleEnumValues.push_back(VERTICAL_BC);
		vectorOfPossibleEnumValues.push_back(VERTICAL_BR);
	}
	return vectorOfPossibleEnumValues;
}

/*static*/ const std::vector<VerticalCardinal::Enum_VerticalCardinal> &VerticalCardinal::getVectorOfReducedPossibleEnumValues()
{
	if (vectorOfReducedPossibleEnumValues.empty())
	{
		vectorOfReducedPossibleEnumValues.push_back(VERTICAL_TR);
		vectorOfReducedPossibleEnumValues.push_back(VERTICAL_TL);
		vectorOfReducedPossibleEnumValues.push_back(VERTICAL_BC);
	}
	return vectorOfReducedPossibleEnumValues;
}

/*static*/ bool VerticalCardinal::canInit(Enum_VerticalCardinal enumCardinal)
{
	const std::vector<Enum_VerticalCardinal> enumValues = VerticalCardinal::getVectorOfPossibleEnumValues();
	for (std::vector<Enum_VerticalCardinal>::const_iterator enumValueIterator = enumValues.begin(); enumValueIterator != enumValues.end(); ++enumValueIterator)
	{
		if (enumCardinal == *enumValueIterator)
		{
			return true;
		}
	}
	return false;
}

/*explicit*/ VerticalCardinal::VerticalCardinal(Enum_VerticalCardinal enumCardinal): enumCardinal(enumCardinal)
{
	if (!VerticalCardinal::canInit(enumCardinal))
	{
		throw CatanClassContractException(__FILE__, __LINE__, "VerticalCardinal::canInit(...) with constructor arguments should be true before creating instance.");
	}
}

VerticalCardinal::Enum_VerticalCardinal VerticalCardinal::getEnum() const
{
	return enumCardinal;
}

bool VerticalCardinal::operator==(const VerticalCardinal &other) const
{
	return enumCardinal == other.enumCardinal;
}

bool VerticalCardinal::operator<(const VerticalCardinal &other) const
{
	return enumCardinal < other.enumCardinal;
}

VerticalCardinal& VerticalCardinal::operator=(const VerticalCardinal& other)
{
    if (this != &other)
    {
        enumCardinal = other.enumCardinal;
    }
    return *this;	
}

}
